﻿using log4net;
using Quartz;
using Quartz.Listener;
using System.Threading;
using System.Threading.Tasks;

namespace QuartzTest
{
    public class LogTriggerListener : TriggerListenerSupport
    {
        static readonly ILog log = LogManager.GetLogger(typeof(LogTriggerListener));
        public override string Name => "LogTriggerListener";
        public override Task TriggerComplete(ITrigger trigger, IJobExecutionContext context, SchedulerInstruction triggerInstructionCode, CancellationToken cancellationToken = default)
        {
            log.Debug($"TriggerComplete trigger.jobKey={trigger.JobKey},JobType={context.JobDetail.JobType}");
            return Task.CompletedTask;
        }
        public override Task TriggerFired(ITrigger trigger, IJobExecutionContext context, CancellationToken cancellationToken = default)
        {
            log.Debug($"TriggerFired trigger.jobKey={trigger.JobKey},JobType={context.JobDetail.JobType}");
            return Task.CompletedTask;
        }
        public override Task TriggerMisfired(ITrigger trigger, CancellationToken cancellationToken = default)
        {
            log.Debug($"TriggerMisfired trigger.jobKey={trigger.JobKey}");
            return Task.CompletedTask;
        }
        public override Task<bool> VetoJobExecution(ITrigger trigger, IJobExecutionContext context, CancellationToken cancellationToken = default)
        {
            log.Debug($"VetoJobExecution trigger.jobKey={trigger.JobKey},context.JobType={context.JobDetail.JobType}");
            return Task.FromResult(false);
        }
    }
}
